package observer;

import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

public class ValoareCurentaHistograma extends Canvas implements Observer, ComponentListener{
	//
	public void componentHidden(ComponentEvent e){}
	public void componentMoved(ComponentEvent e) {}
	public void componentResized(ComponentEvent e) {
		count= getWidth();
		valori= new int[count];
	}
	public void componentShown(ComponentEvent e) {
		count= getWidth();
		valori= new int[count];
	}
	private int count = 100;
	private int [] valori = new int[count];
	
	public ValoareCurentaHistograma(){
		addComponentListener(this);
	}
	////Notifica ob_le at cand se face o schimbare
	public void upDate(Subject s) {
		for (int i = 0; i< count -1 ; i++){
			valori[i] = valori [i+1];
 		}
		valori[count-1]= s.getVal();
		repaint();		
	}
	//Update-uie interfata grafica

	public void update(Graphics g){
		super.update(g);
	}
	//Deseneaza obiectele
	public void paint(Graphics g){
		int w=1;
		for(int i=0;i<count;i++){
			g.fillRect(0 + w*i, 0, w, valori[i]);
		}
	}

//    public void componentHidden(ComponentEvent arg0) {
//            // TODO Auto-generated method stub
//            
//    }

	

}
